package com.fosdata.dpm.controller;


import com.fosdata.dpm.domain.SysXbdev;
import com.fosdata.dpm.entity.dto.ApiResult;
import com.fosdata.dpm.services.SysXbdevServices;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 * 箱变设备表 前端控制器
 * </p>
 *
 * @author gyk
 * @since 2025-10-22
 */
@RestController
public class SysXbdevController {

    @Autowired
    SysXbdevServices sysXbdevServices;

    /**id查**/
    @RequestMapping(value = "/xbdev/getDevById")
    public ApiResult getDevById(String devId){
        if(StringUtils.isBlank(devId)){
            return ApiResult.error("缺少必要参数");
        }
        SysXbdev sysXbdev = sysXbdevServices.getDevById(devId);
        return ApiResult.ok("查询成功",sysXbdev);
    }

    /**添加**/
    @PostMapping(value = "/xbdev/addXbDev")
    public ApiResult addXbDev(@RequestParam SysXbdev sysXbdev){
        if(sysXbdev==null){
            return ApiResult.error("缺少必要参数");
        }
        boolean flag = sysXbdevServices.addXbDev(sysXbdev);
        if(flag){
            return ApiResult.ok("添加成功");
        }
        return ApiResult.error("添加失败");
    }

    /**删除**/
    @GetMapping(value = "/xbdev/deleteXbDev")
    public ApiResult deleteXbDev(String devId){
        if(StringUtils.isEmpty(devId)){
            return ApiResult.error("缺少必要参数");
        }
        boolean flag = sysXbdevServices.deleteXbDev(devId);
        if(flag){
            return ApiResult.ok("删除成功");
        }
        return ApiResult.error("删除失败");
    }

    /**修改**/
    @PostMapping(value = "/xbdev/updateXbDev")
    public ApiResult updateXbDev(@RequestParam SysXbdev sysXbdev){
        if(sysXbdev==null){
            return ApiResult.error("缺少必要参数");
        }
        boolean flag = sysXbdevServices.updateXbDev(sysXbdev);
        if(flag){
            return ApiResult.ok("修改成功");
        }
        return ApiResult.error("修改失败");
    }
}
